package cn.edu.imust.loginregisterdemo.forgetpwd;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.bmob.v3.Bmob;
import cn.bmob.v3.BmobUser;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.UpdateListener;
import cn.edu.imust.loginregisterdemo.R;
import cn.edu.imust.loginregisterdemo.utils.Utils;

public class PwdMsgActivity extends AppCompatActivity {


    @BindView(R.id.oldPwd)
    EditText oldPwd;
    @BindView(R.id.newPwd)
    EditText newPwd;
    @BindView(R.id.confirmPwd)
    EditText confirmPwd;
    @BindView(R.id.confirmModify)
    Button   confirmModify;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pwd_msg);
        ButterKnife.bind(this);
        Bmob.initialize(this, "33452dfaa0b4f1b9b1a5ea2c1818d5f4");
        //myViewModel = new ViewModelProvider(this).get(MyViewModel.class);
    }

    /**
     * 提供旧密码修改密码
     */
    @OnClick(R.id.confirmModify)
    public void onViewClicked(View view) {
        String currentOldPwd = oldPwd.getText().toString().trim();
        String currentNewPwd = newPwd.getText().toString().trim();

        BmobUser.updateCurrentUserPassword(currentOldPwd, currentNewPwd, new UpdateListener() {
            @Override
            public void done(BmobException e) {
                if (e == null) {
                    Toast.makeText(PwdMsgActivity.this, "修改密码成功", Toast.LENGTH_SHORT).show();
                    Utils.showSnackBar(PwdMsgActivity.this, view, "查询成功");
                    finish();
                } else {
                    Utils.showSnackBar(PwdMsgActivity.this, view, "修改密码失败：" + e.getMessage());
                    Toast.makeText(PwdMsgActivity.this, "修改密码失败：" + e.getMessage(), Toast.LENGTH_SHORT).show();
                }
            }
        });
    }

}
